package com.changgou.search.config;



import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    //交换机名称
    public static final String ITEM_Routing_EXCHANGE = "item_routing_exchange";
    //定义队列名称
    public static final String AD_UPDATE_QUEUE="ad_update_queue_before";
    public static final String AD_UPDATE_QUEUE1="ad_update_queue_after";
    //定义用于发送商品下架上架的消息队列的交换机和队列
    public  static  final String GOODS1_EXCHANGE ="goods_exchange";
    public  static  final String GOODS2_EXCHANGE ="goods_exchange";
    public  static  final String GOODS_UP_QUEUE ="goods_up_queue";
    public  static  final String GOODS_DOWN_QUEUE ="GOODS_DOWN_QUEUE";



    //声明交换机
    @Bean("itemroutingexchange")
    public Exchange routingExchange(){
        return ExchangeBuilder.directExchange(ITEM_Routing_EXCHANGE).durable(true).build();
    }
    @Bean("GOODS1_EXCHANGE")
    public Exchange GOODS1_EXCHANGE(){
        return ExchangeBuilder.fanoutExchange(GOODS1_EXCHANGE).durable(true).build();
    }
    @Bean("GOODS2_EXCHANGE")
    public Exchange GOODS2_EXCHANGE(){
        return ExchangeBuilder.fanoutExchange(GOODS2_EXCHANGE).durable(true).build();
    }
    //声明队列
    @Bean("adupdatequeuebefore")
    public Queue queue(){
        return new Queue(AD_UPDATE_QUEUE);
    }
    @Bean("adupdatequeueafter")
    public Queue queue1(){
        return new Queue(AD_UPDATE_QUEUE1);
    }
    @Bean("GOODS_UP_QUEUE")
    public Queue GOODS_UP_QUEUE() {
        return new Queue(GOODS_UP_QUEUE);
    }
    @Bean("GOODS_DOWN_QUEUE")
    public Queue GOODS_DOWN_QUEUE() {
        return new Queue(GOODS_DOWN_QUEUE);
    }

    //绑定交换机和队列
    @Bean
    public Binding itemQueueExchange(@Qualifier("adupdatequeuebefore") Queue queue,
                                     @Qualifier("itemroutingexchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("before").noargs();
    }

    @Bean
    public Binding itemQueueExchange1(@Qualifier("adupdatequeueafter") Queue queue,
                                     @Qualifier("itemroutingexchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("after").noargs();
    }

    @Bean
    public Binding findOouExchange(@Qualifier("GOODS_UP_QUEUE") Queue queue,@Qualifier("GOODS1_EXCHANGE") Exchange exchange){
        return  BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }
    @Bean
    public Binding findOouExchange1(@Qualifier("GOODS_DOWN_QUEUE") Queue queue,@Qualifier("GOODS2_EXCHANGE") Exchange exchange){
        return  BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }

}
